package com.example.es.controller;

import com.example.es.pojo.Content;
import com.example.es.service.ContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@Controller
public class SearchController {


	@Autowired
	private ContentService contentService;

	@GetMapping({"/","/index"})
	public String index(){
		return "index";
	}

	@GetMapping("/parse/{keyword}")
	@ResponseBody
	public Boolean parse(@PathVariable("keyword") String keyword) throws IOException {
		return contentService.parseContent(keyword);
	}


	@GetMapping("/search/{pageNo}/{pageSize}/{keyword}")
	@ResponseBody
	public List<Map<String,Object>> search(@PathVariable("keyword") String keyword,@PathVariable("pageNo") int pageNo,@PathVariable("pageSize") int pageSize) throws IOException {
		return contentService.search(keyword,pageNo,pageSize);
	}


}
